home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 29 / CDT29.iso / e-Mail / WorldClient Pro 2.2.3 / wcsetup.exe / WEBHELP.ZIP / hhapplet / IndexPane.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-10-21  |  7.4 KB  |  400 lines

  1. package hhapplet;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.BorderLayout;
  5. import java.awt.Button;
  6. import java.awt.Color;
  7. import java.awt.Component;
  8. import java.awt.Container;
  9. import java.awt.Event;
  10. import java.awt.Font;
  11. import java.awt.Label;
  12. import java.awt.LayoutManager;
  13. import java.awt.List;
  14. import java.awt.Panel;
  15. import java.awt.TextField;
  16. import java.net.MalformedURLException;
  17. import java.util.Vector;
  18.  
  19. public class IndexPane extends Panel implements DialogDoneTarget {
  20.    protected Applet m_applet;
  21.    protected Vector m_vSecondaryEntries = new Vector();
  22.    protected List m_list;
  23.    protected List m_listHolder;
  24.    protected IndexTree m_forapplelistHolder;
  25.    protected IndexTree m_forapplelist;
  26.    protected TextField m_tfEdit = new TextField();
  27.    protected Button m_btnDisplay = new Button("Display");
  28.    protected IndexSecondaryDialog m_dlgSecondary;
  29.    protected int m_nSelectedIndex = -1;
  30.    protected Panel m_pnlEditArea = new Panel();
  31.    protected Label m_lblEditArea = new Label("Type in the keyword to find:");
  32.    protected LayoutManager m_layEditArea = new BorderLayout(0, 0);
  33.    protected boolean m_bIsIE4 = false;
  34.    protected boolean m_bIsNSWin16 = false;
  35.    protected boolean m_bIsNSWin32 = false;
  36.    protected boolean m_bIsIE3 = false;
  37.    protected boolean m_bMacOS = false;
  38.    protected boolean m_bUseForAppleList = false;
  39.    private LayoutManager m_layout;
  40.    MyThread m_textChangedThread = null;
  41.  
  42.    public boolean gotFocus(Event var1, Object var2) {
  43.       if (this.m_bUseForAppleList) {
  44.          if (var1.target != this.m_tfEdit && var1.target != this.m_forapplelist && var1.target != this.m_btnDisplay) {
  45.             this.m_tfEdit.requestFocus();
  46.          }
  47.       } else if (var1.target != this.m_tfEdit && var1.target != this.m_list && var1.target != this.m_btnDisplay) {
  48.          this.m_tfEdit.requestFocus();
  49.       }
  50.  
  51.       return true;
  52.    }
  53.  
  54.    public void HideList() {
  55.       if (this.m_bUseForAppleList) {
  56.          ((Container)this).add("Center", this.m_forapplelistHolder);
  57.          this.m_forapplelistHolder.show(true);
  58.          this.m_forapplelist.show(false);
  59.       } else {
  60.          ((Container)this).add("Center", this.m_listHolder);
  61.          this.m_listHolder.show(true);
  62.          this.m_list.show(false);
  63.       }
  64.  
  65.       ((Container)this).paintComponents(((Component)this).getGraphics());
  66.    }
  67.  
  68.    public IndexTree getForAppleList() {
  69.       return this.m_forapplelistHolder;
  70.    }
  71.  
  72.    public void MoveSelectionDown() {
  73.    }
  74.  
  75.    public void dialogDone() {
  76.       this.m_dlgSecondary = null;
  77.    }
  78.  
  79.    public IndexPane(Applet var1) {
  80.       this.m_applet = var1;
  81.  
  82.       try {
  83.          if (System.getProperty("os.name").startsWith("MacOS")) {
  84.             this.m_bMacOS = true;
  85.          }
  86.  
  87.          if (System.getProperty("java.vendor").startsWith("Netscape")) {
  88.             if (System.getProperty("os.name").startsWith("16-bit Windows")) {
  89.                this.m_bIsNSWin16 = true;
  90.             } else if (System.getProperty("os.name").startsWith("Windows")) {
  91.                if (System.getProperty("java.version").equalsIgnoreCase("1.02")) {
  92.                   this.m_bUseForAppleList = true;
  93.                }
  94.  
  95.                this.m_bIsNSWin32 = true;
  96.             } else if (System.getProperty("os.name").startsWith("Mac")) {
  97.                this.m_bUseForAppleList = true;
  98.             }
  99.          } else if (System.getProperty("java.vendor").startsWith("Microsoft")) {
  100.             if (System.getProperty("java.version").startsWith("1.1")) {
  101.                this.m_bIsIE4 = true;
  102.             } else {
  103.                this.m_bIsIE3 = true;
  104.             }
  105.  
  106.             if (System.getProperty("os.name").startsWith("Mac")) {
  107.                this.m_bUseForAppleList = true;
  108.             }
  109.  
  110.             if (System.getProperty("java.version").equalsIgnoreCase("1.1")) {
  111.                this.m_bUseForAppleList = true;
  112.             } else if (System.getProperty("java.version").equalsIgnoreCase("1.0.2")) {
  113.                this.m_bUseForAppleList = true;
  114.             }
  115.          }
  116.       } finally {
  117.          ;
  118.       }
  119.  
  120.       if (this.m_bUseForAppleList) {
  121.          this.m_forapplelist = new IndexTree(this);
  122.          this.m_forapplelistHolder = new IndexTree((IndexPane)null);
  123.          this.m_forapplelistHolder.addItem("Loading Index Data...");
  124.       } else {
  125.          this.m_list = new List();
  126.          this.m_listHolder = new List();
  127.          this.m_listHolder.addItem("Loading Index Data...");
  128.          this.m_listHolder.setBackground(Color.white);
  129.       }
  130.  
  131.       this.m_pnlEditArea.setLayout(this.m_layEditArea);
  132.       this.m_pnlEditArea.add("North", this.m_lblEditArea);
  133.       this.m_pnlEditArea.add("Center", this.m_tfEdit);
  134.       this.m_layout = new BorderLayout(2, 2);
  135.       ((Container)this).setLayout(this.m_layout);
  136.       if (!this.m_bUseForAppleList) {
  137.          this.m_list.setBackground(Color.white);
  138.       }
  139.  
  140.       int var2 = WebHelp.GetFontSize();
  141.       if (!this.m_bUseForAppleList) {
  142.          this.m_list.setFont(new Font(WebHelp.GetFontName(), 0, var2));
  143.       }
  144.  
  145.       this.m_tfEdit.setFont(new Font(WebHelp.GetFontName(), 0, var2));
  146.       this.m_btnDisplay.setFont(new Font(WebHelp.GetFontName(), 0, var2));
  147.       if (this.m_bUseForAppleList) {
  148.          ((Container)this).add("Center", this.m_forapplelistHolder);
  149.       } else {
  150.          ((Container)this).add("North", this.m_pnlEditArea);
  151.          ((Container)this).add("Center", this.m_listHolder);
  152.          ((Container)this).add("South", this.m_btnDisplay);
  153.       }
  154.  
  155.       this.m_tfEdit.requestFocus();
  156.    }
  157.  
  158.    public void add(String var1, Vector var2) {
  159.       if (this.m_bUseForAppleList) {
  160.          this.m_forapplelist.addItem(var1);
  161.       } else {
  162.          this.m_list.addItem(var1);
  163.       }
  164.  
  165.       this.m_vSecondaryEntries.addElement(var2);
  166.    }
  167.  
  168.    public boolean mouseUp(Event var1, int var2, int var3) {
  169.       return super.mouseUp(var1, var2, var3);
  170.    }
  171.  
  172.    public List getList() {
  173.       return this.m_list;
  174.    }
  175.  
  176.    public void MoveSelectionPageDown() {
  177.    }
  178.  
  179.    public int FindBaseKeywordForAppleList(int var1, int var2) {
  180.       while(var1 > 0 && var2 < 0 || var1 < this.m_forapplelist.countItems() - 1 && var2 > 0) {
  181.          if (this.m_forapplelist.getItem(var1).charAt(0) != ' ') {
  182.             return var1;
  183.          }
  184.  
  185.          var1 += var2;
  186.       }
  187.  
  188.       return var1;
  189.    }
  190.  
  191.    public void ShowList() {
  192.       if (this.m_bUseForAppleList) {
  193.          this.m_forapplelistHolder.show(false);
  194.          ((Container)this).add("North", this.m_pnlEditArea);
  195.          ((Container)this).add("Center", this.m_forapplelist);
  196.          ((Container)this).add("South", this.m_btnDisplay);
  197.          this.m_forapplelist.show(true);
  198.       } else {
  199.          this.m_listHolder.show(false);
  200.          ((Container)this).add("North", this.m_pnlEditArea);
  201.          ((Container)this).add("Center", this.m_list);
  202.          ((Container)this).add("South", this.m_btnDisplay);
  203.          this.m_list.show(true);
  204.       }
  205.  
  206.       ((Component)this).paintAll(((Component)this).getGraphics());
  207.       ((Container)this).paintComponents(((Component)this).getGraphics());
  208.    }
  209.  
  210.    public TextField getEditBox() {
  211.       return this.m_tfEdit;
  212.    }
  213.  
  214.    public boolean keyUp(Event var1, int var2) {
  215.       if ((var1.target == this.m_forapplelist || var1.target == this.m_list) && System.getProperty("java.version").equals("1.1") && System.getProperty("java.vendor").startsWith("Microsoft") && var1.key == 10) {
  216.          this.action(var1, var1.target);
  217.          return true;
  218.       } else {
  219.          if (this.m_bIsNSWin16) {
  220.             var2 &= 255;
  221.          }
  222.  
  223.          boolean var3 = super.keyUp(var1, var2);
  224.          if (var2 >= 32 && var2 <= 126 && var1.target == this.m_tfEdit) {
  225.             try {
  226.                this.textChanged();
  227.                if (var1.target == this.m_tfEdit) {
  228.                   this.m_tfEdit.requestFocus();
  229.                }
  230.             } finally {
  231.                ;
  232.             }
  233.          }
  234.  
  235.          return var3;
  236.       }
  237.    }
  238.  
  239.    public boolean GetUseForAppleListFlag() {
  240.       return this.m_bUseForAppleList;
  241.    }
  242.  
  243.    public void gotoSelectedIndex() {
  244.       int var1 = -1;
  245.       if (this.m_bUseForAppleList) {
  246.          var1 = this.m_forapplelist.getSelectedIndex();
  247.       } else {
  248.          var1 = this.m_list.getSelectedIndex();
  249.       }
  250.  
  251.       if (var1 != -1) {
  252.          if (((Vector)this.m_vSecondaryEntries.elementAt(var1)).size() == 1) {
  253.             IndexSecondaryEntry var2 = (IndexSecondaryEntry)((Vector)this.m_vSecondaryEntries.elementAt(var1)).elementAt(0);
  254.             if (var2.see_also != null) {
  255.                for(int var3 = 0; var3 < this.m_vSecondaryEntries.size(); ++var3) {
  256.                   if (((Vector)this.m_vSecondaryEntries.elementAt(var3)).size() == 1) {
  257.                      IndexSecondaryEntry var4 = (IndexSecondaryEntry)((Vector)this.m_vSecondaryEntries.elementAt(var3)).elementAt(0);
  258.                      if (var4.name.equals(var2.see_also)) {
  259.                         if (this.m_bUseForAppleList) {
  260.                            this.m_forapplelist.select(var3);
  261.                            if (var3 > 0) {
  262.                               this.m_forapplelist.setTopIndex(var3 - 1);
  263.                            } else {
  264.                               this.m_forapplelist.setTopIndex(var3);
  265.                            }
  266.  
  267.                            this.gotoSelectedIndex();
  268.                            return;
  269.                         }
  270.  
  271.                         if (this.m_list.getVisibleIndex() != var3) {
  272.                            this.m_list.makeVisible(this.m_forapplelist.countItems() - 1);
  273.                            if (var3 > 0) {
  274.                               this.m_list.makeVisible(var3 - 1);
  275.                            } else {
  276.                               this.m_list.makeVisible(var3);
  277.                            }
  278.                         }
  279.  
  280.                         this.m_list.select(var3);
  281.                         this.gotoSelectedIndex();
  282.                         return;
  283.                      }
  284.                   }
  285.                }
  286.  
  287.             } else {
  288.                try {
  289.                   if (var2.frame != null) {
  290.                      this.m_applet.getAppletContext().showDocument(URLFileHandler.makeURL(this.m_applet.getDocumentBase(), var2.local, var2.url), var2.frame);
  291.                   } else {
  292.                      this.m_applet.getAppletContext().showDocument(URLFileHandler.makeURL(this.m_applet.getDocumentBase(), var2.local, var2.url), "_self");
  293.                   }
  294.                } catch (MalformedURLException var5) {
  295.                }
  296.             }
  297.          } else {
  298.             if (this.m_dlgSecondary != null) {
  299.                this.m_dlgSecondary.closeDialog();
  300.                this.m_dlgSecondary = null;
  301.             }
  302.  
  303.             this.m_dlgSecondary = new IndexSecondaryDialog(this.m_applet, (Vector)this.m_vSecondaryEntries.elementAt(var1), this);
  304.             this.m_dlgSecondary.show();
  305.             this.m_dlgSecondary.getList().requestFocus();
  306.          }
  307.       }
  308.    }
  309.  
  310.    public int FindBaseKeyword(int var1, int var2) {
  311.       while(var1 > 0 && var2 < 0 || var1 < this.m_list.countItems() - 1 && var2 > 0) {
  312.          if (this.m_list.getItem(var1).charAt(0) != ' ') {
  313.             return var1;
  314.          }
  315.  
  316.          var1 += var2;
  317.       }
  318.  
  319.       return var1;
  320.    }
  321.  
  322.    protected void finalize() throws Throwable {
  323.       if (this.m_bUseForAppleList) {
  324.          this.m_forapplelist.clear();
  325.          this.m_forapplelist = null;
  326.       } else {
  327.          this.m_list.clear();
  328.          this.m_list = null;
  329.       }
  330.  
  331.       super.finalize();
  332.    }
  333.  
  334.    public boolean action(Event var1, Object var2) {
  335.       this.gotoSelectedIndex();
  336.       return true;
  337.    }
  338.  
  339.    public boolean handleEvent(Event var1) {
  340.       if (System.getProperty("java.version").startsWith("1.1.5") && this.m_bIsNSWin32 && var1.id == 401 && var1.key == 10 && var1.target == this.m_btnDisplay) {
  341.          this.action(var1, var1.target);
  342.          return true;
  343.       } else if (this.m_bIsIE4 && var1.id == 1001 && var1.target == this.m_tfEdit) {
  344.          return true;
  345.       } else {
  346.          if (var1.target == this.m_list) {
  347.             if (var1.id == 701 && this.m_list.getSelectedIndex() != this.m_nSelectedIndex) {
  348.                String var2 = this.m_list.getSelectedItem();
  349.                this.m_nSelectedIndex = this.m_list.getSelectedIndex();
  350.                if (var2 != null) {
  351.                   this.m_tfEdit.setText(var2);
  352.                   this.m_applet.showStatus(var2);
  353.                }
  354.             }
  355.          } else if (var1.target == this.m_tfEdit && var1.id == 403) {
  356.             switch (var1.key) {
  357.                case 1002:
  358.                   this.MoveSelectionPageUp();
  359.                   break;
  360.                case 1003:
  361.                   this.MoveSelectionPageDown();
  362.                   break;
  363.                case 1004:
  364.                   this.MoveSelectionUp();
  365.                   break;
  366.                case 1005:
  367.                   this.MoveSelectionDown();
  368.             }
  369.          }
  370.  
  371.          return super.handleEvent(var1);
  372.       }
  373.    }
  374.  
  375.    public void textChanged() {
  376.       if (this.m_textChangedThread == null) {
  377.          this.m_textChangedThread = new MyThread(this);
  378.          this.m_textChangedThread.setPriority(4);
  379.          this.m_textChangedThread.start();
  380.       } else {
  381.          ++this.m_textChangedThread.m_bResearch;
  382.       }
  383.    }
  384.  
  385.    public void MoveSelectionUp() {
  386.    }
  387.  
  388.    public void MoveSelectionPageUp() {
  389.    }
  390.  
  391.    public boolean keyDown(Event var1, int var2) {
  392.       if ((var1.target == this.m_forapplelist || var1.target == this.m_list) && (!System.getProperty("java.version").equals("1.1") || !System.getProperty("java.vendor").startsWith("Microsoft")) && var1.key == 10) {
  393.          this.action(var1, var1.target);
  394.          return true;
  395.       } else {
  396.          return super.keyDown(var1, var2);
  397.       }
  398.    }
  399. }
  400.